import instacne from "../request";
import type { Ref } from "vue";
import qs from "qs";

// 获取推荐列表数据
interface HomeBrandData {
  pageNum: number;
  pageSize: number;
  brandName?: string;
  recommendStatus?: number;
}

interface ResData {
  brandId: number;
  brandName: string;
  id: number;
  recommendStatus: number;
  sort: number;
}

interface HomeBrandResData {
  list: ResData[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}

const homeBrandApi = (data: HomeBrandData): Promise<HomeBrandResData> => {
  return instacne.get(
    `/home/brand/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&brandName=${data.brandName}`
  );
};

// 修改品牌推荐排序 /home/brand/update/sort/{id}
interface HomeBrandUpdateSortData {
  id: number;
  sort: number;
}

// 筛选数据请求 /brand/list
const brandListApi = (data: HomeBrandData): Promise<HomeBrandResData> => {
  return instacne.get(
    `/brand/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}`
  );
};

// 修改品牌推荐排序 /home/brand/update/sort/{id}
interface HomeBrandUpdateSortData {
  id: number;
  sort: number;
}

const HomeBrandUpdateSortDataApi = (data: HomeBrandUpdateSortData) => {
  return instacne.post(
    `/home/brand/update/sort/${data.id}?sort=${data.sort}&id=${data.id}`
  );
};

// 删除 /home/brand/delete
interface HomeBrandDeleteData {
  ids: number;
}

const HomeBrandDeleteDataApi = (data: HomeBrandDeleteData) => {
  return instacne.post("/home/brand/delete", qs.stringify(data));
};

// 筛选数据添加 /home/brand/create
let homeBrandCreate = (data: object) => {
  return instacne.post("/home/brand/create", data);
};

// 编辑秒杀时间段 /flashSession/update/
interface FlashSessionUpdate {
  createTime: null;
  endTime: string;
  id: number;
  name: string;
  startTime: string;
  status: number;
}

const FlashSessionUpdateApi = (data: FlashSessionUpdate) => {
  return instacne.post(`/flashSession/update/${data.id}`, data);
};

// 更改是否推荐状态 /home/brand/update/recommendStatus
interface HomeBrandUpdateRecommendStart {
  ids: number;
  recommendStatus: number;
}

const HomeBrandUpdateRecommendStartApi = (
  data: HomeBrandUpdateRecommendStart
) => {
  return instacne.post(
    "/home/brand/update/recommendStatus",
    qs.stringify(data)
  );
};

export {
  HomeBrandDeleteDataApi,
  homeBrandCreate,
  FlashSessionUpdateApi,
  HomeBrandUpdateRecommendStartApi,
  homeBrandApi,
  HomeBrandUpdateSortDataApi,
  brandListApi,
};
